package xin.mydreams.mybill.widget.bill.reposirtory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import xin.mydreams.mybill.widget.bill.entity.Bill;
import xin.mydreams.mybill.widget.bill.entity.ClassInfo;

import java.util.Date;
import java.util.List;

public interface BillRepostory extends JpaRepository<Bill,String> {

    public Page<Bill> findByCreatedTimeBetween(Date begintime, Date endTime, Pageable pageable);

    @Query(" SELECT b FROM Bill b WHERE DATE_FORMAT ( b.createdTime, '%Y%m' ) =:time")
    public Page<Bill> findByCreatedTime(@Param("time") String time, Pageable pageable);


    @Query("select new xin.mydreams.mybill.widget.bill.entity.ClassInfo(b.createdUser , sum (b.money)) from Bill b where DATE_FORMAT ( b.createdTime, '%Y%m' ) =:time group by b.createdUser")
    public List<ClassInfo> groupByCreatedUser(@Param("time") String time);
}
